package SHNOPData
{
	import model.SHNOPModel.StatisticsType;
	
	import mx.collections.ArrayCollection;
	import mx.collections.ArrayList;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	public class BaseQuery
	{
		private var remoteObject:RemoteObject;
		//定义接收的函数
		public var onReceive_GetNTPlanList:Function;
		public var onReceive_BQ_GetZiDianContent:Function;
		public var onReceive_GetNTPlanHistoryList:Function;
		public var onReceive_GetNTPlanInfo:Function;
		//获取操作日志
		public var onReceive_GetOperateLogList:Function;
		public var onReceive_InsertOrEditNTPlan:Function;
		public var onReceive_InsertOrEditZhanDian:Function;
		public var onReceive_InsertOrEditDuanKou:Function;
		public var onReceive_InsertOrEditPinLv:Function;
		public var onReceive_InsertOrEditRuWang:Function;
		public var onReceive_EditNTPlanDetail:Function;
		
		public var onReceive_DeleteNTPlanInfo:Function;
		public var onReceive_DeleteZhanDianInfo:Function;
		public var onReceive_DeleteDuanKouInfo:Function;
		public var onReceive_DeletePinLvInfo:Function;
		public var onReceive_DeleteRuWangInfo:Function;
	
		public var onReceive_StatisticNtPlanByType:Function;
		public var onReceiveGetBelongScheme:Function;
		public var onReceiveGetTDBelongScheme:Function;

		public var onReceive_GetSession:Function;
		public var onReceive_DestroySession:Function;
		public var onReceive_GetTemplets:Function;
		
		public var onReceive_ExportHistoryExcel:Function;
		public function BaseQuery()
		{
			remoteObject  = new RemoteObject("fluorine");
			remoteObject.source = "SHNOPData.BaseQuery";
			
			remoteObject.GetNTPlanList.addEventListener("result",GetNTPlanList_ResultHandler);
			remoteObject.BQ_GetZiDianContent.addEventListener("result",BQ_GetZiDianContent_ResultHandler);
			remoteObject.GetOperateLogList.addEventListener("result",GetOperateLogList_ResultHandler);
			remoteObject.InsertOrEditNTPlan.addEventListener("result",InsertOrEditNTPlan_ResultHandler);
			remoteObject.InsertOrEditZhanDianInfo.addEventListener("result",InsertOrEditZhanDian_ResultHandler);
			remoteObject.InsertOrEditDuanKouInfo.addEventListener("result",InsertOrEditDuanKou_ResultHandler);
			remoteObject.InsertOrEditPinLvInfo.addEventListener("result",InsertOrEditPinLv_ResultHandler);
			remoteObject.InsertOrEditRuWangInfo.addEventListener("result",InsertOrEditRuWang_ResultHandler);
			remoteObject.EditNTPlanDetail.addEventListener("result",EditNTPlanDetail_ResultHandler);
			
			remoteObject.DeleteNTPlanInfo.addEventListener("result",DeleteNTPlanInfo_ResultHandler);
			remoteObject.DeleteZhanDianInfo.addEventListener("result",DeleteZhanDianInfo_ResultHandler);
			remoteObject.DeleteDuanKouInfo.addEventListener("result",DeleteDuanKouInfo_ResultHandler);
			remoteObject.DeletePinLvInfo.addEventListener("result",DeletePinLvInfo_ResultHandler);
			remoteObject.DeleteRuWangInfo.addEventListener("result",DeleteRuWangInfo_ResultHandler);
			
			remoteObject.StatisticNtPlanByType.addEventListener("result",StatisticNtPlanByType_ResultHandler);
			
			remoteObject.GetBelongScheme.addEventListener("result",GetBelongSchemeResultHandler);
			remoteObject.GetTDBelongScheme.addEventListener("result",GetTDBelongSchemeResultHandler);
			
			remoteObject.GetNTPlanHistoryList.addEventListener("result",GetNTPlanHistoryList_ResultHandler);
			remoteObject.GetNTPlanInfo.addEventListener("result",GetNTPlanInfo_ResultHandler);
			
			remoteObject.GetSession.addEventListener("result",GetSession_ResultHandler);
			remoteObject.DestroySession.addEventListener("result",DestroySession_ResultHandler);
			remoteObject.GetTemplets.addEventListener("result",GetTemplets_ResultHandler);
			remoteObject.ExportHistoryExcel.addEventListener("result",ExportHistoryExcel_ResultHandler);
			remoteObject.addEventListener("fault", onFault);
			
			onReceive_GetNTPlanList = null;
			onReceive_BQ_GetZiDianContent = null;
			onReceive_GetNTPlanHistoryList = null;
			onReceive_GetNTPlanInfo = null;
			
			onReceive_InsertOrEditNTPlan = null;
			onReceive_InsertOrEditZhanDian = null;
			onReceive_InsertOrEditDuanKou = null;
			onReceive_InsertOrEditPinLv = null;
			onReceive_InsertOrEditRuWang = null;
			onReceive_EditNTPlanDetail = null;
			
			onReceive_DeleteNTPlanInfo = null;
			onReceive_DeleteZhanDianInfo = null;
			onReceive_DeleteDuanKouInfo = null;
			onReceive_DeletePinLvInfo = null;
			onReceive_DeleteRuWangInfo = null;
			onReceive_GetOperateLogList=null;
			
			onReceiveGetBelongScheme=null;
			onReceiveGetTDBelongScheme=null;
			
			onReceive_StatisticNtPlanByType=null;
 			onReceive_GetSession=null;
			onReceive_DestroySession=null;
		}
		public function setCredentials( userid:String, password:String ):void
		{
			remoteObject.setCredentials( userid, password );
		}
		
		
		/*public function Test(test:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.Test(test);
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function Test_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_Test)
				onReceive_Test(event.result);
		}*/
		
		//====================
		//*****获取规划基础信息列表***
		//====================
		public function GetNTPlanList(searchItem:Object,responder:IResponder = null ):void
		{
			remoteObject.showBusyCursor=true;
			var asyncToken:AsyncToken = remoteObject.GetNTPlanList(searchItem);
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetNTPlanList_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetNTPlanList)
				onReceive_GetNTPlanList(event.result);
		}
		//====================
		public function GetNTPlanHistoryList(guihuaid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetNTPlanHistoryList(guihuaid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetNTPlanHistoryList_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetNTPlanHistoryList)
				onReceive_GetNTPlanHistoryList(event.result);
		}
		//====================
		public function GetNTPlanInfo(guihuaid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetNTPlanInfo(guihuaid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetNTPlanInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetNTPlanInfo)
				onReceive_GetNTPlanInfo(event.result);
		}
		//====================
		public function BQ_GetZiDianContent(boundObjStr:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.BQ_GetZiDianContent(boundObjStr);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function BQ_GetZiDianContent_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_BQ_GetZiDianContent)
				onReceive_BQ_GetZiDianContent(event.result);
		}
		
		//====================
		//*****编辑规划信息部分****
		//====================
		public function InsertOrEditNTPlan(oldPlanInfo:Object,newPlanInfo:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.InsertOrEditNTPlan(oldPlanInfo,newPlanInfo);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function InsertOrEditNTPlan_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_InsertOrEditNTPlan)
				onReceive_InsertOrEditNTPlan(event.result);
		}
		//====================
		public function InsertOrEditZhanDian(oldZhanDianInfo:Object,newZhanDianInfo:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.InsertOrEditZhanDianInfo(oldZhanDianInfo,newZhanDianInfo);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function InsertOrEditZhanDian_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_InsertOrEditZhanDian)
				onReceive_InsertOrEditZhanDian(event.result);
		}
		//====================
		public function InsertOrEditDuanKou(oldDuanKouInfo:Object,newDuanKouInfo:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.InsertOrEditDuanKouInfo(oldDuanKouInfo,newDuanKouInfo);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function InsertOrEditDuanKou_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_InsertOrEditDuanKou)
				onReceive_InsertOrEditDuanKou(event.result);
		}
		//====================
		public function InsertOrEditPinLv(oldPinLvInfo:Object,newPinLvInfo:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.InsertOrEditPinLvInfo(oldPinLvInfo,newPinLvInfo);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function InsertOrEditPinLv_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_InsertOrEditPinLv)
				onReceive_InsertOrEditPinLv(event.result);
		}
		//====================
		public function InsertOrEditRuWang(oldRuWangInfo:Object,newRuWangInfo:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.InsertOrEditRuWangInfo(oldRuWangInfo,newRuWangInfo);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function InsertOrEditRuWang_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_InsertOrEditRuWang)
				onReceive_InsertOrEditRuWang(event.result);
		}
		//====================
		public function EditNTPlanDetail(oldPlanData:Object,newPlanData:Object,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.EditNTPlanDetail(oldPlanData,newPlanData);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function EditNTPlanDetail_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_EditNTPlanDetail)
				onReceive_EditNTPlanDetail(event.result);
		}
		
		//====================
		//*****删除规划信息部分****
		//====================
		public function DeleteNTPlanInfo(guihuaid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteNTPlanInfo(guihuaid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteNTPlanInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteNTPlanInfo)
				onReceive_DeleteNTPlanInfo(event.result);
		}
		//====================
		public function DeleteZhanDianInfo(guihuaid:String,zhandianid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteZhanDianInfo(guihuaid,zhandianid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteZhanDianInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteZhanDianInfo)
				onReceive_DeleteZhanDianInfo(event.result);
		}
		//====================
		public function DeleteDuanKouInfo(guihuaid:String,duankouid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteDuanKouInfo(guihuaid,duankouid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteDuanKouInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteDuanKouInfo)
				onReceive_DeleteDuanKouInfo(event.result);
		}
		//====================
		public function DeletePinLvInfo(guihuaid:String,pinlvid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeletePinLvInfo(guihuaid,pinlvid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeletePinLvInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeletePinLvInfo)
				onReceive_DeletePinLvInfo(event.result);
		}
		//====================
		public function DeleteRuWangInfo(guihuaid:String,ruwangid:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.DeleteRuWangInfo(guihuaid,ruwangid);
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function DeleteRuWangInfo_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DeleteRuWangInfo)
				onReceive_DeleteRuWangInfo(event.result);
		}
		/*
		
		*/
		public function GetOperateLogList(guihuaid:String,responder:IResponder = null):void
		{
			var asyncToken:AsyncToken = remoteObject.GetOperateLogList(guihuaid);
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetOperateLogList_ResultHandler(event:ResultEvent):void{
			if(null != onReceive_GetOperateLogList)
				onReceive_GetOperateLogList(event.result);
		}
		//=========================
		//*********统计信息部分********
		//=========================

		public function StatisticNtPlanByType(statisticsType:StatisticsType,
											 responder:IResponder = null):void
		{
			var asyncToken:AsyncToken = remoteObject.StatisticNtPlanByType(statisticsType);
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function StatisticNtPlanByType_ResultHandler(event:ResultEvent):void{
			if(null != onReceive_StatisticNtPlanByType)
				onReceive_StatisticNtPlanByType(event.result);
		}
		public function GetBelongScheme(responder:IResponder = null):void
		{
			var asyncToken:AsyncToken = remoteObject.GetBelongScheme();
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetBelongSchemeResultHandler(event:ResultEvent):void{
			if(null != onReceiveGetBelongScheme)
				onReceiveGetBelongScheme(event.result);
		}
		public function GetTDBelongScheme(responder:IResponder = null):void
		{
			var asyncToken:AsyncToken = remoteObject.GetTDBelongScheme();
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetTDBelongSchemeResultHandler(event:ResultEvent):void{
			if(null != onReceiveGetTDBelongScheme)
				onReceiveGetTDBelongScheme(event.result);
		}
		
		public function GetSession(responder:IResponder = null):void
		{
			remoteObject.showBusyCursor=true;
			var asyncToken:AsyncToken = remoteObject.GetSession();
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function DestroySession(responder:IResponder = null):void
		{
			remoteObject.showBusyCursor=true;
			var asyncToken:AsyncToken = remoteObject.DestroySession();
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetSession_ResultHandler(event:ResultEvent):void{
			if(null !=onReceive_GetSession)
				onReceive_GetSession(event.result);
		}
		
		public function DestroySession_ResultHandler(event:ResultEvent):void{
			if(null !=onReceive_DestroySession)
				onReceive_DestroySession(event.result);
		}
		public function GetTemplets(responder:IResponder = null):void
		{
			remoteObject.showBusyCursor=true;
			var asyncToken:AsyncToken = remoteObject.GetTemplets();
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function GetTemplets_ResultHandler(event:ResultEvent):void{
			if(null !=onReceive_GetTemplets)
				onReceive_GetTemplets(event.result);
		}
		public function ExportHistoryExcel(array:ArrayCollection,type:String,responder:IResponder = null):void
		{
			remoteObject.showBusyCursor=true;
			var asyncToken:AsyncToken = remoteObject.ExportHistoryExcel(array,type);
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function ExportHistoryExcel_ResultHandler(event:ResultEvent):void{
			if(null !=onReceive_ExportHistoryExcel)
				onReceive_ExportHistoryExcel(event.result);
		}
		//=========================
		//*************************
		//=========================
		public function onFault (event:FaultEvent):void
		{
			if(event.fault.faultCode=="Client.Authorization")
			{
				SHNOP.fireSessionTimeout();
			}
			else
			{
				Alert.show("string:"+event.fault.faultString+" code:"+event.fault.faultCode+" detail:"+event.fault.faultDetail,"发生错误");
			}
		}
	}
}
